{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "67689a70-f4e3-4640-a61e-75b976b51b5d",
   "metadata": {},
   "source": [
    "# 函数与文件"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "97a2a413-70c7-49a4-b5ff-fbfa81e54039",
   "metadata": {},
   "source": [
    "## 函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "305f528f-41f9-43ff-8c7a-4f396e709f3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg width=\"400\" height=\"400\" style=\"fill:none; stroke-linecap:round;\">\n",
       "    <rect width=\"100%\" height=\"100%\" fill=\"#F3F3F7\" />\n",
       "\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 100,100 150,100 150,70 100,70 100,100\" />'\n",
       "\n",
       "<g transform=\"rotate(-90.0,100.0,100.0) translate(100.0, 100.0)\">\n",
       "    <circle stroke=\"#63A375\" stroke-width=\"2\" fill=\"transparent\" r=\"5.5\" cx=\"0\" cy=\"0\"/>\n",
       "    <polygon points=\"0,12 2,9 -2,9\" style=\"fill:#63A375;stroke:#63A375;stroke-width:2\"/>\n",
       "</g>\n",
       "\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import jupyturtle as t\n",
    "import math\n",
    "\n",
    "t.make_turtle(animate=True,delay=0.02, width=400, height=400)\n",
    "#定义一个画矩形的函数\n",
    "def rectangle(x,y,width,height):   #定义函数名，括号设置变量\n",
    "    t.jump_to(x,y)                 #写下代码\n",
    "    for i in range(4):\n",
    "        if i==0 or i==2:\n",
    "             t.fd(width)\n",
    "        else:\n",
    "            t.fd(height)\n",
    "        t.lt(90)\n",
    "            \n",
    "rectangle(x=100,y=100,width=50,height=30)    #调用函数   "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3dbf2579-9a50-48c6-b5a8-945f74faeac1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg width=\"400\" height=\"400\" style=\"fill:none; stroke-linecap:round;\">\n",
       "    <rect width=\"100%\" height=\"100%\" fill=\"#F3F3F7\" />\n",
       "\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 104.9,119.1 295.1,119.1 141.2,230.9 200,50 258.8,230.9 104.9,119.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,150\" />'\n",
       "\n",
       "<g transform=\"rotate(-90.0,200,150) translate(200, 150)\">\n",
       "    <circle stroke=\"#63A375\" stroke-width=\"2\" fill=\"transparent\" r=\"5.5\" cx=\"0\" cy=\"0\"/>\n",
       "    <polygon points=\"0,12 2,9 -2,9\" style=\"fill:#63A375;stroke:#63A375;stroke-width:2\"/>\n",
       "</g>\n",
       "\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import jupyturtle as t\n",
    "import math\n",
    "\n",
    "t.make_turtle(animate=True,delay=0.02, width=400, height=400)\n",
    "#画一个五角星\n",
    "def pentagram(x,y,r):\n",
    "    t.jump_to(x-r*math.cos(18/180*math.pi),y-r*math.sin(18/180*math.pi))\n",
    "    \n",
    "    for i in range(5):\n",
    "        t.fd(2*r*math.cos(18/180*math.pi))\n",
    "        t.right(144)\n",
    "    t.jump_to(x,y)\n",
    "        \n",
    "\n",
    "\n",
    "pentagram(x=200,y=150,r=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "6c5f847e-b9d1-4541-af67-3f9e51292059",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg width=\"400\" height=\"400\" style=\"fill:none; stroke-linecap:round;\">\n",
       "    <rect width=\"100%\" height=\"100%\" fill=\"#F3F3F7\" />\n",
       "\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 104.9,169.1 293.2,169.1 140.9,279.8 199,100.7 257.2,279.8 104.9,169.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 105.8,169.4 292.3,169.4 141.4,279 199,101.7 256.7,279 105.8,169.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 106.8,169.7 291.3,169.7 142,278.2 199,102.7 256.1,278.2 106.8,169.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 107.7,170 290.4,170 142.6,277.4 199,103.7 255.5,277.4 107.7,170\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 108.7,170.3 289.4,170.3 143.2,276.5 199,104.7 254.9,276.5 108.7,170.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 109.6,170.6 288.4,170.6 143.8,275.7 199,105.7 254.3,275.7 109.6,170.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 110.6,171 287.5,171 144.4,274.9 199,106.7 253.7,274.9 110.6,171\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 111.6,171.3 286.5,171.3 145,274.1 199,107.7 253.1,274.1 111.6,171.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 112.5,171.6 285.6,171.6 145.6,273.3 199,108.7 252.5,273.3 112.5,171.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 113.5,171.9 284.6,171.9 146.1,272.5 199,109.7 251.9,272.5 113.5,171.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 114.4,172.2 283.7,172.2 146.7,271.7 199,110.7 251.4,271.7 114.4,172.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 115.4,172.5 282.7,172.5 147.3,270.9 199,111.7 250.8,270.9 115.4,172.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 116.3,172.8 281.8,172.8 147.9,270.1 199,112.7 250.2,270.1 116.3,172.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 117.3,173.1 280.8,173.1 148.5,269.3 199,113.7 249.6,269.3 117.3,173.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 118.2,173.4 279.9,173.4 149.1,268.5 199,114.7 249,268.5 118.2,173.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 119.2,173.7 278.9,173.7 149.7,267.6 199,115.7 248.4,267.6 119.2,173.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 120.1,174 278,174 150.3,266.8 199,116.7 247.8,266.8 120.1,174\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 121.1,174.4 277,174.4 150.9,266 199,117.7 247.2,266 121.1,174.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 122,174.7 276.1,174.7 151.4,265.2 199,118.7 246.7,265.2 122,174.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 123,175 275.1,175 152,264.4 199,119.7 246.1,264.4 123,175\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 123.9,175.3 274.2,175.3 152.6,263.6 199,120.7 245.5,263.6 123.9,175.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 124.9,175.6 273.2,175.6 153.2,262.8 199,121.7 244.9,262.8 124.9,175.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 125.8,175.9 272.3,175.9 153.8,262 199,122.7 244.3,262 125.8,175.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 126.8,176.2 271.3,176.2 154.4,261.2 199,123.7 243.7,261.2 126.8,176.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 127.7,176.5 270.4,176.5 155,260.4 199,124.7 243.1,260.4 127.7,176.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 128.7,176.8 269.4,176.8 155.6,259.6 199,125.7 242.5,259.6 128.7,176.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 129.6,177.1 268.5,177.1 156.1,258.7 199,126.7 242,258.7 129.6,177.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 130.6,177.4 267.5,177.4 156.7,257.9 199,127.7 241.4,257.9 130.6,177.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 131.5,177.8 266.6,177.8 157.3,257.1 199,128.7 240.8,257.1 131.5,177.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 132.5,178.1 265.6,178.1 157.9,256.3 199,129.7 240.2,256.3 132.5,178.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 133.4,178.4 264.7,178.4 158.5,255.5 199,130.7 239.6,255.5 133.4,178.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 134.4,178.7 263.7,178.7 159.1,254.7 199,131.7 239,254.7 134.4,178.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 135.3,179 262.8,179 159.7,253.9 199,132.7 238.4,253.9 135.3,179\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 136.3,179.3 261.8,179.3 160.3,253.1 199,133.7 237.8,253.1 136.3,179.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 137.2,179.6 260.9,179.6 160.8,252.3 199,134.7 237.3,252.3 137.2,179.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 138.2,179.9 259.9,179.9 161.4,251.5 199,135.7 236.7,251.5 138.2,179.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 139.1,180.2 259,180.2 162,250.7 199,136.7 236.1,250.7 139.1,180.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 140.1,180.5 258,180.5 162.6,249.9 199,137.7 235.5,249.9 140.1,180.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 141,180.8 257.1,180.8 163.2,249 199,138.7 234.9,249 141,180.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 142,181.1 256.1,181.1 163.8,248.2 199,139.7 234.3,248.2 142,181.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 142.9,181.5 255.2,181.5 164.4,247.4 199,140.7 233.7,247.4 142.9,181.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 143.9,181.8 254.2,181.8 165,246.6 199,141.7 233.1,246.6 143.9,181.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 144.8,182.1 253.3,182.1 165.5,245.8 199,142.7 232.6,245.8 144.8,182.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 145.8,182.4 252.3,182.4 166.1,245 199,143.7 232,245 145.8,182.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 146.7,182.7 251.4,182.7 166.7,244.2 199,144.7 231.4,244.2 146.7,182.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 147.7,183 250.4,183 167.3,243.4 199,145.7 230.8,243.4 147.7,183\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 148.6,183.3 249.5,183.3 167.9,242.6 199,146.7 230.2,242.6 148.6,183.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 149.6,183.6 248.5,183.6 168.5,241.8 199,147.7 229.6,241.8 149.6,183.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 150.5,183.9 247.6,183.9 169.1,241 199,148.7 229,241 150.5,183.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 151.5,184.2 246.6,184.2 169.7,240.1 199,149.7 228.4,240.1 151.5,184.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 152.4,184.5 245.7,184.5 170.2,239.3 199,150.7 227.9,239.3 152.4,184.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 153.4,184.9 244.7,184.9 170.8,238.5 199,151.7 227.3,238.5 153.4,184.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 154.3,185.2 243.7,185.2 171.4,237.7 199,152.7 226.7,237.7 154.3,185.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 155.3,185.5 242.8,185.5 172,236.9 199,153.7 226.1,236.9 155.3,185.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 156.3,185.8 241.8,185.8 172.6,236.1 199,154.7 225.5,236.1 156.3,185.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 157.2,186.1 240.9,186.1 173.2,235.3 199,155.7 224.9,235.3 157.2,186.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 158.2,186.4 239.9,186.4 173.8,234.5 199,156.7 224.3,234.5 158.2,186.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 159.1,186.7 239,186.7 174.4,233.7 199,157.7 223.7,233.7 159.1,186.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 160.1,187 238,187 174.9,232.9 199,158.7 223.1,232.9 160.1,187\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 161,187.3 237.1,187.3 175.5,232.1 199,159.7 222.6,232.1 161,187.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 162,187.6 236.1,187.6 176.1,231.2 199,160.7 222,231.2 162,187.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 162.9,187.9 235.2,187.9 176.7,230.4 199,161.7 221.4,230.4 162.9,187.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 163.9,188.3 234.2,188.3 177.3,229.6 199,162.7 220.8,229.6 163.9,188.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 164.8,188.6 233.3,188.6 177.9,228.8 199,163.7 220.2,228.8 164.8,188.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 165.8,188.9 232.3,188.9 178.5,228 199,164.7 219.6,228 165.8,188.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 166.7,189.2 231.4,189.2 179.1,227.2 199,165.7 219,227.2 166.7,189.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 167.7,189.5 230.4,189.5 179.7,226.4 199,166.7 218.4,226.4 167.7,189.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 168.6,189.8 229.5,189.8 180.2,225.6 199,167.7 217.9,225.6 168.6,189.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 169.6,190.1 228.5,190.1 180.8,224.8 199,168.7 217.3,224.8 169.6,190.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 170.5,190.4 227.6,190.4 181.4,224 199,169.7 216.7,224 170.5,190.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 171.5,190.7 226.6,190.7 182,223.2 199,170.7 216.1,223.2 171.5,190.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 172.4,191 225.7,191 182.6,222.3 199,171.7 215.5,222.3 172.4,191\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 173.4,191.3 224.7,191.3 183.2,221.5 199,172.7 214.9,221.5 173.4,191.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 174.3,191.7 223.8,191.7 183.8,220.7 199,173.7 214.3,220.7 174.3,191.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 175.3,192 222.8,192 184.4,219.9 199,174.7 213.7,219.9 175.3,192\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 176.2,192.3 221.9,192.3 184.9,219.1 199,175.7 213.2,219.1 176.2,192.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 177.2,192.6 220.9,192.6 185.5,218.3 199,176.7 212.6,218.3 177.2,192.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 178.1,192.9 220,192.9 186.1,217.5 199,177.7 212,217.5 178.1,192.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 179.1,193.2 219,193.2 186.7,216.7 199,178.7 211.4,216.7 179.1,193.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 180,193.5 218.1,193.5 187.3,215.9 199,179.7 210.8,215.9 180,193.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 181,193.8 217.1,193.8 187.9,215.1 199,180.7 210.2,215.1 181,193.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 181.9,194.1 216.2,194.1 188.5,214.3 199,181.7 209.6,214.3 181.9,194.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 182.9,194.4 215.2,194.4 189.1,213.4 199,182.7 209,213.4 182.9,194.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 183.8,194.7 214.3,194.7 189.6,212.6 199,183.7 208.5,212.6 183.8,194.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 184.8,195.1 213.3,195.1 190.2,211.8 199,184.7 207.9,211.8 184.8,195.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 185.7,195.4 212.4,195.4 190.8,211 199,185.7 207.3,211 185.7,195.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 186.7,195.7 211.4,195.7 191.4,210.2 199,186.7 206.7,210.2 186.7,195.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 187.6,196 210.5,196 192,209.4 199,187.7 206.1,209.4 187.6,196\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 188.6,196.3 209.5,196.3 192.6,208.6 199,188.7 205.5,208.6 188.6,196.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 189.5,196.6 208.6,196.6 193.2,207.8 199,189.7 204.9,207.8 189.5,196.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 190.5,196.9 207.6,196.9 193.8,207 199,190.7 204.3,207 190.5,196.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 191.4,197.2 206.7,197.2 194.3,206.2 199,191.7 203.8,206.2 191.4,197.2\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 192.4,197.5 205.7,197.5 194.9,205.4 199,192.7 203.2,205.4 192.4,197.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 193.3,197.8 204.8,197.8 195.5,204.5 199,193.7 202.6,204.5 193.3,197.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 194.3,198.1 203.8,198.1 196.1,203.7 199,194.7 202,203.7 194.3,198.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 195.2,198.5 202.9,198.5 196.7,202.9 199,195.7 201.4,202.9 195.2,198.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 196.2,198.8 201.9,198.8 197.3,202.1 199,196.7 200.8,202.1 196.2,198.8\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 197.1,199.1 201,199.1 197.9,201.3 199,197.7 200.2,201.3 197.1,199.1\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 198.1,199.4 200,199.4 198.5,200.5 199,198.7 199.6,200.5 198.1,199.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 199,199.7 199,199.7 199,199.7 199,199.7 199,199.7 199,199.7\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,200\" />'\n",
       "\n",
       "<g transform=\"rotate(-90.0,200,200) translate(200, 200)\">\n",
       "    <circle stroke=\"#63A375\" stroke-width=\"2\" fill=\"transparent\" r=\"5.5\" cx=\"0\" cy=\"0\"/>\n",
       "    <polygon points=\"0,12 2,9 -2,9\" style=\"fill:#63A375;stroke:#63A375;stroke-width:2\"/>\n",
       "</g>\n",
       "\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import jupyturtle as t\n",
    "import math\n",
    "t.make_turtle(animate=True,delay=0, width=400, height=400)\n",
    "t.set_default(TURTLE_DELAY=0)\n",
    "#画一个实心五角星\n",
    "def pentagram1(x,y,r):\n",
    "    for i in range(r):\n",
    "        t.jump_to(x-r*math.cos(18/180*math.pi),y-r*math.sin(18/180*math.pi))\n",
    "        r=r-1\n",
    "        for j in range(5):\n",
    "             t.fd(2*r*math.cos(18/180*math.pi))\n",
    "             t.right(144)\n",
    "    t.jump_to(x,y)\n",
    "    \n",
    "            \n",
    "        \n",
    "    \n",
    "pentagram1(200,200,100)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "682a432d-44b9-4b73-ad69-c37729c832bc",
   "metadata": {},
   "source": [
    "# 文件（File）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b375bc1d-a670-41ea-863c-c42fb99c2f21",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  79.326   2.971   1.254  69.256  49.119  85.393  35.545  39.124   1.079  52.282\n",
      "  73.777  99.514  77.338  79.211  17.094  63.092  81.235  97.350  67.738  16.075\n",
      "  58.285   5.364  79.838  40.635  24.189  22.954  85.427  12.907  73.903  49.382\n",
      "   2.734  33.324  29.959  87.097   7.001  71.915  60.788   6.884  97.175  23.563\n",
      "  47.268  57.942  70.187  20.903  27.901  79.967   7.926  19.779   5.198  45.466\n",
      "  47.027  49.061  58.045  51.613  24.804  49.103   1.267  52.438  11.641  73.641\n",
      "  49.824  56.402  62.709  51.522   6.835  16.038  16.326  43.303  58.477  31.629\n",
      "  52.583  62.286  73.528  81.770  39.733  26.988  50.614  34.098  99.190  76.582\n",
      "  56.018  26.136  63.979  31.043  49.114  79.980  86.728  15.163   5.251   2.602\n",
      "  58.098  66.406  32.147   9.221   3.707  62.368  98.402  84.009  37.128  35.400\n",
      "\n"
     ]
    }
   ],
   "source": [
    "file = open(\"test.txt\",\"r\")\n",
    "content = file.read()\n",
    "file.close()\n",
    "print(content)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "f2e2aa8f-218b-4f1b-9027-7d6964adf568",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'str'>\n",
      "  73.777  99.514  77.338  79.211  17.094  63.092  81.235  97.350  67.738  16.075\n",
      "\n"
     ]
    }
   ],
   "source": [
    "file = open(\"test.txt\",\"r\")\n",
    "lines=file.readlines()\n",
    "print(type(content))\n",
    "print(lines[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "fe7a868a-39de-4f53-a6e8-0c72d213249f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['  79.326   2.971   1.254  69.256  49.119  85.393  35.545  39.124   1.079  52.282\\n  73.777  99.514  77.338  79.211  17.094  63.092  81.235  97.350  67.738  16.075\\n  58.285   5.364  79.838  40.635  24.189  22.954  85.427  12.907  73.903  49.382\\n   2.734  33.324  29.959  87.097   7.001  71.915  60.788   6.884  97.175  23.563\\n  47.268  57.942  70.187  20.903  27.901  79.967   7.926  19.779   5.198  45.466\\n  47.027  49.061  58.045  51.613  24.804  49.103   1.267  52.438  11.641  73.641\\n  49.824  56.402  62.709  51.522   6.835  16.038  16.326  43.303  58.477  31.629\\n  52.583  62.286  73.528  81.770  39.733  26.988  50.614  34.098  99.190  76.582\\n  56.018  26.136  63.979  31.043  49.114  79.980  86.728  15.163   5.251   2.602\\n  58.098  66.406  32.147   9.221   3.707  62.368  98.402  84.009  37.128  35.400\\n']\n"
     ]
    }
   ],
   "source": [
    "with open(\"test.txt\",\"r\") as file:    #with自动关掉文件在完成这个程序之后\n",
    "    content = file.read()\n",
    "print(content.split(','))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "00404bd7-ee9e-4e39-ad46-90bbd170db68",
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = ['Hello,world!']\n",
    "with open('test.txt','a') as file:  #'w'写，有覆盖的风险，'a'增加，在原基础上增加\n",
    "    file.writelines(lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "716c3787-8c83-4add-ad5c-d1b3bc4d005c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "18.38,19.91,90.32,19.82,48.17,40.31,55.87,32.69,74.18,29.56,\n",
      "50.88,30.34,91.05,84.30,43.88, 8.69,67.03,30.86,92.51, 8.85,\n",
      "95.29,26.54,62.35,17.28,96.80,33.73,96.65,45.87,85.34,73.44,\n",
      "68.51, 7.98,69.90,69.36,95.13,35.44,89.74,57.11,10.73,78.05,\n",
      "78.79,22.75,53.45,31.67,34.29,83.07,80.88,98.17,85.36,99.11,\n",
      "82.61,74.66,27.25,21.72,42.50,75.91,11.06,81.45,34.39,19.13,\n",
      "48.91,13.09,34.31,34.36,80.32,10.00,32.18,38.70,80.49,71.56,\n",
      "41.59,82.55,88.70,41.44,77.14,58.27,74.65,51.09,63.41,25.21,\n",
      "31.27,64.41,46.76,83.28,29.72,77.84,27.96,50.71,92.44,12.67,\n",
      "85.57,62.65,72.60, 3.62, 2.24,57.31,95.67,15.06,70.11,77.98,\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "s = ''\n",
    "for i  in range(100):\n",
    "    num = random.random()*100\n",
    "    s = s + f\"{num:5.2f}\"+\",\"\n",
    "    if (i+1)%10 ==0:\n",
    "        s = s + '\\n'\n",
    "        \n",
    "print(s)\n",
    "\n",
    "with open(\"test.txt\",\"w\") as file:\n",
    "    file.write(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f57dfe3-0e9c-4bf3-95db-56f3713c1603",
   "metadata": {},
   "source": [
    "## 作业一、实现欧盟旗的12颗星显示"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b9e5b77a-a8cf-4f1c-ab20-6defc471455c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<svg width=\"600\" height=\"400\" style=\"fill:none; stroke-linecap:round;\">\n",
       "    <rect width=\"100%\" height=\"100%\" fill=\"#F3F3F7\" />\n",
       "\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 300,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 400,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 390.5,196.9 409.5,196.9 394.1,208.1 400,190 405.9,208.1 390.5,196.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 386.6,150\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 377.1,146.9 396.1,146.9 380.7,158.1 386.6,140 392.5,158.1 377.1,146.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 350,113.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 340.5,110.3 359.5,110.3 344.1,121.5 350,103.4 355.9,121.5 340.5,110.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 300,100\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 290.5,96.9 309.5,96.9 294.1,108.1 300,90 305.9,108.1 290.5,96.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 250,113.4\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 240.5,110.3 259.5,110.3 244.1,121.5 250,103.4 255.9,121.5 240.5,110.3\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 213.4,150\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 203.9,146.9 222.9,146.9 207.5,158.1 213.4,140 219.3,158.1 203.9,146.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 200,200\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 190.5,196.9 209.5,196.9 194.1,208.1 200,190 205.9,208.1 190.5,196.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 213.4,250\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 203.9,246.9 222.9,246.9 207.5,258.1 213.4,240 219.3,258.1 203.9,246.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 250,286.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 240.5,283.5 259.5,283.5 244.1,294.7 250,276.6 255.9,294.7 240.5,283.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 300,300\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 290.5,296.9 309.5,296.9 294.1,308.1 300,290 305.9,308.1 290.5,296.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 350,286.6\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 340.5,283.5 359.5,283.5 344.1,294.7 350,276.6 355.9,294.7 340.5,283.5\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 386.6,250\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 377.1,246.9 396.1,246.9 380.7,258.1 386.6,240 392.5,258.1 377.1,246.9\" />'\n",
       "\n",
       "<path stroke=\"#663399\" stroke-width=\"2\" d=\"M 300,200\" />'\n",
       "\n",
       "<g transform=\"rotate(-90.0,300,200) translate(300, 200)\">\n",
       "    <circle stroke=\"#63A375\" stroke-width=\"2\" fill=\"transparent\" r=\"5.5\" cx=\"0\" cy=\"0\"/>\n",
       "    <polygon points=\"0,12 2,9 -2,9\" style=\"fill:#63A375;stroke:#63A375;stroke-width:2\"/>\n",
       "</g>\n",
       "\n",
       "</svg>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import jupyturtle as t\n",
    "import math\n",
    "\n",
    "t.make_turtle(animate=True,delay=0.000002, width=600, height=400,)\n",
    "t.set_default(TURTLE_DELAY=0)\n",
    "\n",
    "\n",
    "def flag(X,Y,R,r):\n",
    "     \n",
    "    \n",
    "    for i in range(12):\n",
    "        x = X+R*math.cos(30*i/180*math.pi)\n",
    "        y = Y-R*math.sin(30*i/180*math.pi)\n",
    "        t.jump_to(x,y)\n",
    "        \n",
    "        t.jump_to(x-r*math.cos(18/180*math.pi),y-r*math.sin(18/180*math.pi))\n",
    "        \n",
    "       \n",
    "        for k in range(5):\n",
    "            t.fd(2*r*math.cos(18/180*math.pi))\n",
    "            t.right(144)\n",
    "            \n",
    "    t.jump_to(X,Y)\n",
    "     \n",
    "        \n",
    "        \n",
    "    \n",
    "flag(300,200,100,10)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "942018bc-0d6f-40b3-89fd-6f8a313d113e",
   "metadata": {},
   "source": [
    "## 作业二、 写入100个数据到文件中，每行10个数据，共10行。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "9638a38f-bc05-449e-8229-ea93fff8563e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   86,   66,   48,   77,   20,   89,   97,    6,   81,   49\n",
      "   51,   72,    2,   41,   89,   86,   59,   30,   58,   75\n",
      "   46,   50,   44,    3,   39,   43,   10,   76,   43,   16\n",
      "   72,   88,   42,   55,   51,   45,   96,   34,   97,   69\n",
      "   27,   49,   87,    7,   10,   68,   67,   40,   75,   98\n",
      "    5,   61,   53,   21,   42,   17,   66,   15,   16,   46\n",
      "   18,   31,   81,   75,   27,   79,   56,   25,   44,   86\n",
      "   57,   96,   99,   96,   19,   94,   12,   49,   19,   38\n",
      "   86,   44,   36,   72,   94,   67,   34,   38,   73,   60\n",
      "   64,   52,   22,   38,   80,   88,   65,   81,   56,    9\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "s = ''\n",
    "for i  in range(100):\n",
    "    num = random.random()*100\n",
    "    if (i+1)%10 != 0:\n",
    "        s =  s + f\"{num:5.0f}\" + \",\"\n",
    "    else:\n",
    "        s =  s + f\"{num:5.0f}\" + \"\\n\"\n",
    "print(s)\n",
    "\n",
    "with open(\"test.txt\",\"w\") as file:\n",
    "    file.write(s)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8821e778-dfe5-4cca-964c-adb409ab46f4",
   "metadata": {},
   "source": [
    "## 作业三、写一个读数的程序，打开生成的文件 ，读出所有的内容 ，然后拆分出100个数据，存入列表中。最后统计各个分数段的数据个数，即0-10，10-20，……，90-100. （区间为左闭右开）。打印出结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "122f0e60-677b-4b23-912a-528faab8b866",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "分数段 0-9: 10 个\n",
      "分数段 10-19: 6 个\n",
      "分数段 20-29: 8 个\n",
      "分数段 30-39: 8 个\n",
      "分数段 40-49: 9 个\n",
      "分数段 50-59: 13 个\n",
      "分数段 60-69: 12 个\n",
      "分数段 70-79: 9 个\n",
      "分数段 80-89: 11 个\n",
      "分数段 90-99: 14 个\n"
     ]
    }
   ],
   "source": [
    "import random\n",
    "\n",
    "with open('test.txt', 'w') as file:\n",
    "    for i in range(100):\n",
    "        file.write(\"%8.3f\" % random.uniform(0, 100))\n",
    "        if (i + 1) % 10 == 0:\n",
    "            file.write(\"\\n\")\n",
    "\n",
    "\n",
    "with open('test.txt', 'r') as file:\n",
    "    lines = file.readlines()\n",
    "\n",
    "data_list = []\n",
    "\n",
    "for line in lines:\n",
    "    numbers = line.strip().split()\n",
    "    data_list.extend(numbers)\n",
    "\n",
    "score_counts = {f\"{i*10}-{(i+1)*10-1}\": 0 for i in range(10)}\n",
    "for number in data_list:\n",
    "    score = float(number)\n",
    "    for i in range(10):\n",
    "        if i*10 <= score < (i+1)*10:\n",
    "            score_counts[f\"{i*10}-{(i+1)*10-1}\"] += 1\n",
    "            break\n",
    "\n",
    "for score_range, count in score_counts.items():\n",
    "    print(f\"分数段 {score_range}: {count} 个\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0cb8def0-47d8-446e-8fc8-01a5bc79a28d",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
